﻿using MangoMes.Commont.Domain.Department;
using MangoMes.Commont.DTOs.CommontFiles;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;
using System.Runtime.ConstrainedExecution;
using System;
using MangoMes.Commont.DapperHelps;

namespace ManagoMes.Read.API.Applications.Departmentes
{
    public class DepartmentsAddHandler : IRequestHandler<DepartmentsAddCommond, int>
    {
        private readonly IBateRepository<Departments> _depart;

        public DepartmentsAddHandler(IBateRepository<Departments> _depart)
        {
            this._depart = _depart;
        }
        /// <summary>
        /// 部门添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> Handle(DepartmentsAddCommond request, CancellationToken cancellationToken)
        {
           
            Departments depar=new Departments();
            DapperHelper helper = new DapperHelper();
            depar.Departmentid = request.Departmentid;
            depar.DepartmentName = request.DepartmentName;
            depar.LevelName= request.LevelName;
            depar.isNo = request.isNo;
            depar.DepartmentNo = request.DepartmentNo;
            depar.AreaName = request.AreaName;
            depar.TypeName = request.TypeName;

            string conn = helper.MangoMesWrite;

            string str = $"insert into department values (@departmentId,@LevelName,@DepartmentName,@isNo,@TypeName,@departmentNo,@AreaName)";
            var ai = await _depart.Add(str, depar, conn);
          
            return ai;

        }
    }
}
